/**
 * @file ngine.cpp
 * @author Suk Robert Koh (srkoh87z@gmail.com)
 */

#include "ngine/client/ngineclient.h"

NGClient *NGineClient::client = 0;

/**
 * Default constructor for NGine class
 */
NGineClient::NGineClient()
{

}

/**
 * Destructor for NGine class
 */
NGineClient::~NGineClient()
{

}

/**
 * Initializes the NGine
 *
 * @param	const char *	Address of the server to connect to
 * @param	int				Port number of the server to connect to
 * @param	int				Other properties (currently not used)
 */
void NGineClient::init(const char *address, int port, int property)
{
	if(client == 0)
		client = new NGTcpClient(address, port);
}

/**
 * Gets the size of the receive message queue
 *
 * @return	int		Size of the receive message queue
 */
int NGineClient::getQueueSize()
{
	return client->getRecvQueueSize();
}

/**
 * Gets the first message of the receive message queue
 *
 * @return	NGMessage *		Pointer to the first message of the receive message queue
 */
NGMessage *NGineClient::getFirstMessage()
{
	return client->getFirstMessage();
}

/**
 * Sends message to the server
 *
 * @param	BYTE			Type of the message to be sent
 * @param	const char *	Data of the message to be sent
 */
void NGineClient::sendToServer(BYTE type, const char *message)
{
	// create message object
	NGMessage *msg = new NGMessage();
	msg->setType(type);
	msg->setData(message);

	// send to server
	client->sendToServer(msg);
}
